<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询全部数据</title>
</head>
<body>
<sql:setDataSource var="ds1" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf-8"
     user="root"  password="Root123@"/>
 
<sql:query dataSource="${ds1}" var="result">
SELECT * from user;
</sql:query>
<h1>JSP 数据库实例 - select</h1>
	<table border="1" width="100%">
		<tr>
			<th>id</th>
			<th>name</th>
			<th>age</th>
			<th>sex</th>
		</tr>
		<c:forEach var="row" items="${result.rows}">
			<tr>
				<td><c:out value="${row.id}" /></td>
				<td><c:out value="${row.name}" /></td>
				<td><c:out value="${row.age}" /></td>
				<td><c:out value="${row.sex}" /></td>
			</tr>
		</c:forEach>
	</table>
</body>
</html>